home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Science / Gnuplot 3.5 / docs / doc2hlp.c < prev    next >
C/C++ Source or Header  |  1993-11-03  |  2KB  |  102 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: doc2hlp.c 3.38.2.6 1992/11/14 02:25:48 woo Exp $";
  3. #endif
  4.  
  5.  
  6. /*
  7.  * doc2hlp.c  -- program to convert Gnuplot .DOC format to 
  8.  * VMS help (.HLP) format.
  9.  *
  10.  * This involves stripping all lines with a leading ?,
  11.  * @, #, or %.
  12.  * Modified by Russell Lang from hlp2ms.c by Thomas Williams 
  13.  *
  14.  * usage:  doc2hlp [file.doc [file.hlp]]
  15.  *
  16.  * Original version by David Kotz used the following one line script!
  17.  * sed '/^[?@#%]/d' file.doc > file.hlp
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <ctype.h>
  22.  
  23. #define MAX_LINE_LEN    256
  24. #define TRUE 1
  25. #define FALSE 0
  26.  
  27. main(argc,argv)
  28. int argc;
  29. char **argv;
  30. {
  31. FILE * infile;
  32. FILE * outfile;
  33.     infile = stdin;
  34.     outfile = stdout;
  35.     if (argc > 3) {
  36.         fprintf(stderr,"Usage: %s [infile [outfile]]\n", argv[0]);
  37.         exit(1);
  38.     }
  39.     if (argc >= 2) 
  40.         if ( (infile = fopen(argv[1],"r")) == (FILE *)NULL) {
  41.             fprintf(stderr,"%s: Can't open %s for reading\n",
  42.                 argv[0], argv[1]);
  43.             exit(1);
  44.         }
  45.     if (argc == 3)
  46.         if ( (outfile = fopen(argv[2],"w")) == (FILE *)NULL) {
  47.             fprintf(stderr,"%s: Can't open %s for writing\n",
  48.                 argv[0], argv[2]);
  49.         }
  50.     
  51.     convert(infile,outfile);
  52.     exit(0);
  53. }
  54.  
  55.  
  56. convert(a,b)
  57.     FILE *a,*b;
  58. {
  59.     static char line[MAX_LINE_LEN];
  60.  
  61.     while (fgets(line,MAX_LINE_LEN,a)) {
  62.        process_line(line, b);
  63.     }
  64. }
  65.  
  66. process_line(line, b)
  67.     char *line;
  68.     FILE *b;
  69. {
  70.     static int line_count = 0;
  71.  
  72.     line_count++;
  73.  
  74.     switch(line[0]) {        /* control character */
  75.        case '?': {            /* interactive help entry */
  76.           break;            /* ignore */
  77.        }
  78.        case '@': {            /* start/end table */
  79.           break;            /* ignore */
  80.        }
  81.        case '#': {            /* latex table entry */
  82.           break;            /* ignore */
  83.        }
  84.        case '%': {            /* troff table entry */
  85.           break;            /* ignore */
  86.        }
  87.        case '\n':            /* empty text line */
  88.        case ' ': {            /* normal text line */
  89.           (void) fputs(line,b); 
  90.           break;
  91.        }
  92.        default: {
  93.           if (isdigit(line[0])) { /* start of section */
  94.             (void) fputs(line,b); 
  95.           } else
  96.             fprintf(stderr, "unknown control code '%c' in column 1, line %d\n", 
  97.                   line[0], line_count);
  98.           break;
  99.        }
  100.     }
  101. }
  102.